package com.atwisdom.star.controller;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.vo.ActionData;
import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.core.bsl.modelClass.consume.Impl.ConsumeInstanceBslServiceImpl;
import com.atwisdom.star.core.bsl.modelClass.consume.Impl.ConsumeModelBslServiceImpl;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.log.aop.StarAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/consume")
public class ConsumeController {
    private ConsumeModelBslServiceImpl consumeModelBslService;
    private ConsumeInstanceBslServiceImpl consumeInstanceBslService;

    @Autowired
    public void setConsumeModelBslService(ConsumeModelBslServiceImpl consumeModelBslService) {
        this.consumeModelBslService = consumeModelBslService;
    }

    @Autowired
    public void setConsumeInstanceBslService(ConsumeInstanceBslServiceImpl consumeInstanceBslService) {
        this.consumeInstanceBslService = consumeInstanceBslService;
    }

    @StarAnnotation
    @PostMapping(value = "/model")
    public ResultInfo<?> consumeModel(@RequestBody List<ActionData<JSONObject>> actionDataList) throws BusinessException {
        return consumeModelBslService.responseFactory(actionDataList);
    }

    /**
     * @param actionDataList 接收参数据
     * @return 返回结果
     * @throws BusinessException 异常
     */
    @StarAnnotation
    @PostMapping(value = "/instance")
    public ResultInfo<?> consumeInstance(@RequestBody List<ActionData<JSONObject>> actionDataList) throws BusinessException {
        return consumeInstanceBslService.responseFactory(actionDataList);
    }
}
